import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:hixing_app/assets/r_img.dart';
import 'package:hixing_app/const/color_res.dart';
import 'package:hixing_app/const/gaps.dart';
import 'package:hixing_app/utils/export_utils.dart';
import 'package:hixing_app/widgets/custom_dropdown_menu/custom_dropdown_menu.dart';
import 'package:hixing_app/widgets/custom_dropdown_menu/custom_dropdown_menu_model.dart';
import 'package:hixing_app/widgets/custom_tabbar.dart';
import 'package:hixing_app/widgets/search_input/search_input.dart';

class TestCommunityPage extends StatefulWidget {
  @override
  _TestCommunityPageState createState() => _TestCommunityPageState();
}

class _TestCommunityPageState extends State<TestCommunityPage>
    with SingleTickerProviderStateMixin {
  TextEditingController _searchCtrl = TextEditingController();
  List<String> tabList = ["动态", "教程", "精选"];
  List<DropdownMenuModel> drowdownList = [
    DropdownMenuModel(label: "获赞", value: 0),
    DropdownMenuModel(label: "下载", value: 1),
    DropdownMenuModel(label: "时间", value: 2),
  ];

  bool textShowMore = false;
  late TabController tabController =
      TabController(length: tabList.length, vsync: this);

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _searchCtrl.dispose();
    tabController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: ColorRes.bgColor,
        body: Column(
          children: [
            ColoredBox(
              color: Colors.white,
              child: Column(
                children: [
                  Gaps.getVGap(ScreenUI.topSafeHeight + 5),
                  _buildAppBar(),
                  CommonTabbar(
                    tabList: tabList,
                    controller: tabController,
                    marginLeft: 0,
                  ),
                  Gaps.vGap5,
                  Row(
                    children: [
                      const Spacer(),
                      CustomDropdownMenu(
                        sortList: drowdownList,
                        onSelect: (val) {},
                      ),
                    ],
                  ),
                  Gaps.vGap5,
                ],
              ),
            ),
            Expanded(
                child: ListView.builder(
                    itemCount: 20,
                    padding: EdgeInsets.only(
                        left: 10,
                        right: 10,
                        bottom: ScreenUI.bottomSafeHeight + 10),
                    itemBuilder: (ctx, index) {
                      return _buildDataList();
                    }))
          ],
        ));
  }

  Widget _buildDataList() {
    return Container(
      margin: const EdgeInsets.only(top: 10),
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(4)),
      padding: EdgeInsets.all(10),
      child: Column(
        children: [
          Row(
            children: [
              Image.asset(
                ImgR.imgBgPenguin,
                width: 30,
                height: 30,
              ),
              Gaps.hGap10,
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    "LaserPecker",
                    style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
                  ),
                  Text(
                    "2024-03-15 16:20:02",
                    style: TextStyle(fontSize: 10, color: Colors.grey),
                  )
                ],
              ),
              const Spacer(),
              Container(
                padding: EdgeInsets.symmetric(horizontal: 6, vertical: 2),
                decoration: BoxDecoration(
                    border: Border.all(
                      color: Color(0xFF111111),
                    ),
                    borderRadius: BorderRadius.circular(4)),
                child: Text(
                  "已关注",
                  style: TextStyle(fontSize: 12),
                ),
              ),
              Gaps.hGap20,
              Icon(
                Icons.more,
                size: 20,
              ),
            ],
          ),
          Gaps.vGap10,
          Text(
            "收拾收拾大大啊肯定山东快书防守打法的丰富的开发点击点击放得开甲方收到反馈家属的富士康大姐夫上岛咖啡结算单开发拒收到付sdk福建省打客服拒收到付上看看快快快快快快卡卡卡快快快",
            maxLines: !textShowMore ? 3 : null,
          ),
          Gaps.vGap10,
          Row(
            children: [
              Text(
                "查看翻译",
                style: TextStyle(fontSize: 14, color: Colors.orangeAccent),
              ),
              const Spacer(),
              GestureDetector(
                onTap: () {
                  setState(() {
                    textShowMore = !textShowMore;
                  });
                },
                child: Text(
                  !textShowMore ? "显示更多" : "收起",
                  style: TextStyle(fontSize: 14, color: Colors.orangeAccent),
                ),
              )
            ],
          ),
          Gaps.vGap5,
          Image.asset(ImgR.imgBgJiguang),
          Gaps.vGap10,
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 20.0),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Row(
                  children: [
                    Icon(
                      Icons.favorite,
                      color: Colors.grey,
                      size: 18,
                    ),
                    Gaps.hGap2,
                    Text(
                      "1",
                      style: TextStyle(color: Colors.grey, fontSize: 12),
                    )
                  ],
                ),
                Row(
                  children: [
                    Icon(
                      Icons.phone_in_talk,
                      color: Colors.grey,
                      size: 18,
                    ),
                    Gaps.hGap2,
                    Text(
                      "1",
                      style: TextStyle(color: Colors.grey, fontSize: 12),
                    )
                  ],
                ),
                Row(
                  children: [
                    Icon(
                      Icons.download,
                      color: Colors.grey,
                      size: 18,
                    ),
                    Gaps.hGap2,
                    Text(
                      "1",
                      style: TextStyle(color: Colors.grey, fontSize: 12),
                    )
                  ],
                ),
              ],
            ),
          )
        ],
      ),
    );
  }

  Widget _buildAppBar() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 10),
      child: Row(
        children: [
          Container(
            width: 26,
            height: 26,
            decoration: BoxDecoration(
                color: Colors.greenAccent,
                borderRadius: BorderRadius.circular(30)),
            child: Icon(Icons.add),
          ),
          Expanded(
            child: Padding(
              padding: EdgeInsets.only(bottom: 8),
              child: SearchInput(
                controller: _searchCtrl,
                showSearchIcon: false,
                fillColor: ColorRes.borderF6,
                suffixWidget: Icon(
                  Icons.send,
                  size: 14,
                ),
                paddingHorizontal: 10,
              ),
            ),
          ),
          Icon(Icons.notification_add),
        ],
      ),
    );
  }
}
